<!-- 设备维护 -->
<template>
  <div  class="dashboard-editor-container">
    <el-row style="background: #fff; padding: 16px 16px 0; margin-bottom: 32px">
      <div class="wrap">
        <div class="parameType">
          <div class="title">设备维护</div>
          <div class="content">
            <p style="height:30px">请选择正确的升级包上传升级，升级后版本将不可恢复，升级后设备将会自动重启。</p>
            <el-button style="float:right;" size="small" @click="clickfile()">软件升级</el-button>
            <p style="height:30px">设备重启将导致数据容灾备份功能短时间失效</p>
            
            
            <el-button size="small" @click="restartTheDevice('Reboot')">设备重启</el-button>
            <el-button size="small" @click="restartTheDevice('Shutdown')">设备关机</el-button>
            <input style="display:none" type="file" ref="upfile" accept=".gz" @change="changefile($event)">
          </div>
        </div>
        <div class="parameType">
          <div class="title">制作文件同步磁盘</div>
          <div class="content">
            <p>请保持设备上只插入需要制作为文件同步移动存储介质，如果插入多个可能会导致数据丢失！
              <br>
              <el-checkbox v-model="IsSecurityDisk" :false-label="0" :true-label="1"></el-checkbox>
              <span style="margin-left:10px">开启数据文件安全存储模式（采用加密磁盘模式，存储介质必须在设备上才能正常使用）</span>
            </p>
            
            <el-button size="small" @click="restartTheDevice('CreateBackupDisk')">制作文件同步分区</el-button>
            <!-- <input style="display:none" type="file" ref="upfile" accept=".gz" @change="restartTheDevice('CreateBackupDisk')"> -->
          </div>
        </div>
        <!-- <div class="parameType">
          <div class="title">关机重启</div>
          <div class="content">
            <p>设备重启将导致域名加速功能短时间失效</p>
            
          </div>
        </div> -->
        <div class="parameType">
          <div class="title">工具下载</div>
          <div class="content">
            <p style="height:30px">FTP工具：提供一种内置开源FTP安全访问工具，不建议使用不安全FTP</p>
            <!-- <div> -->
              <el-button size="small" @click="DownloadFile1()">下载安全FTP工具</el-button>
              <!-- <el-button size="small" @click="DownloadFile2()">加速上网助手（压缩格式）</el-button> -->
            <!-- </div> -->
            <p style="height:30px">终端代理：提供在需要进行自动备份终端安装的软件</p>
            <div>
              <!-- <el-button size="small" @click="DownloadFile1()">加速上网助手（运行格式）</el-button> -->
              <el-button size="small" @click="DownloadFile2()">下载自动备份软件</el-button>
            </div>
          </div>
        </div>
        <div class="parameType">
          <div class="title">制作扩展备份磁盘</div>
          <div class="content">
            <p>请保持设备上只插入需要制作的扩展存储介质，如果插入多个可能会导致数据丢失！
              <br>
              <el-checkbox style="margin-right:0" v-model="IsSecurityDisk2" :false-label="0" :true-label="1"></el-checkbox>
              <span style="margin-left:10px">开启数据文件安全存储模式（采用加密磁盘模式，存储介质必须在设备上才能正常使用）</span>
              <br>
              <el-checkbox v-model="IsIncludeGhostDisk" :false-label="0" :true-label="1"></el-checkbox>
              <span style="margin-left:10px">扩展磁盘提供系统备份分区（转储分区和系统备份分区各占50%空间）</span>
              
            </p>
            
            <el-button size="small" @click="restartTheDevice('CreateExtDisk')">制作扩展备份分区</el-button>
            <!-- <input style="display:none" type="file" ref="upfile" accept=".gz" @change=""> -->
          </div>
        </div>
        
        <!-- <div class="parameType">
          <div class="title">下载亚马逊商城助手</div>
          <div class="content">
            <p>该助手工具提供每个亚马逊账号使用一个同一个公网IP地址访问功能。该工具为纯绿色软件，运行后对系统没有任何影响。如果下载或者运行过程中有杀毒引擎提示异常，请放行或添加到信任。</p>
            <el-button size="small" @click="DownloadFile3()" style="margin-top:40px;">下载助手工具</el-button>
          </div>
        </div> -->
      </div>
    </el-row>
  </div>
</template>

<script>
import { connrequest, downloadfile, uploadfile } from '@/api/firstPage'
import { getToken } from '@/utils/auth' // get token from cookie
export default {
  data() {
    return {
      IsSecurityDisk:0,
      IsSecurityDisk2:0,
      IsIncludeGhostDisk:0
    }
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods: {
    restartTheDevice(status){
      let IsSecurityDisk = 0;
      let title = '';
      if (status === 'Reboot') {
        title ='设备重启将导致数据容灾备份功能短时间失效, 是否继续?'
      }else if(status === 'Shutdown'){
        title = '设备关机将导致数据容灾备份功能失效, 是否继续?'
      }else if(status === 'CreateBackupDisk'){
        title = '此操作将制作文件同步磁盘，是否继续'
        IsSecurityDisk = this.IsSecurityDisk;
      }else{
        title = '此操作将制作扩展备份磁盘，是否继续'
        IsSecurityDisk = this.IsSecurityDisk2;
      }
      this.$confirm(title, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const data = {
          Data:{
            Action: status,
            IsSecurityDisk:IsSecurityDisk,
            IsIncludeGhostDisk:this.IsIncludeGhostDisk
          }
        }
        const res = await connrequest('ExecDeviceMaint', data)
        if(res.Status.StatusCode === 0) {
          this.$message.success('操作成功')
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });          
      });
    },
    clickfile(){
      this.$refs.upfile.click()
    },
    async DownloadFile1(){
      window.open('https://192.168.20.190/WinsCP.exe');
      // const data = {
      //   Data:{
      //     FileName: 'WinsCP.exe'
      //   }
      // }
      // const res = await downloadfile('DownloadPublicFile', data)
      // let blobUrl = window.URL.createObjectURL(new Blob([res]));
      // const a = document.createElement('a');
      // a.style.display = 'none';
      // a.download = 'WinsCP.exe';
      // a.href = blobUrl;
      // a.click();
    },
    async DownloadFile2(){
      window.open('https://192.168.20.190/SecClientRsycSvc.exe');
      // const data = {
      //   Data:{
      //     FileName: 'SecClientRsycSvc.exe'
      //   }
      // }
      // const res = await downloadfile('DownloadPublicFile', data)
      // let blobUrl = window.URL.createObjectURL(new Blob([res]));
      // const a = document.createElement('a');
      // a.style.display = 'none';
      // a.download = 'SecClientRsycSvc.exe';
      // a.href = blobUrl;
      // a.click();
    },
    async DownloadFile3(){
      const data = {
        Data:{
          FileName: '亚马逊商城助手.rar'
        }
      }
      const res = await downloadfile('DownloadPublicFile', data)
      let blobUrl = window.URL.createObjectURL(new Blob([res]));
      const a = document.createElement('a');
      a.style.display = 'none';
      a.download = '亚马逊商城助手.rar';
      a.href = blobUrl;
      a.click();
    },
    async changefile(e){
      let formData = new FormData();
      formData.append('CmdCode', "Upgrade");
      formData.append('FileName', "event_to_rule");
      formData.append('file', e.target.files[0]);
      formData.append('Token', getToken());
      const res = await uploadfile('Upgrade',formData)
      if(res.Status.StatusCode === 0) {
        this.$refs.upfile.value = ''
        const confirmText = [`软件升级成功，新升级功能需要重启设备才能生效。`,`您需要立刻重启设备吗？(设备重启将导致导致数据容灾备份功能短时间失效)`]
        const newDatas = []
          const h = this.$createElement
          for (const i in confirmText) {
            newDatas.push(h('p', null, confirmText[i]))
          }
        this.$confirm('提示', {
          message: h('div', null, newDatas),
          confirmButtonText: '重启设备',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          const data = {
            Data:{
              Action: 'Reboot'
            }
          }
          await connrequest('ExecDeviceMaint', data)
          this.$store.dispatch('user/resetToken').then(() => {
            location.reload()
          })
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
.parameType{
  width: 650px;
  margin-right:50px;
  margin-top: 10px !important;
  margin-bottom: 10px !important;
}
.wrap{
  display: flex;
  flex-wrap: wrap;
}
.content{
  margin-top: 20px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: flex-end;
  .el-button{
    padding: 10px 20px;
  }
  div{
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content:center;
    .el-button{
      margin-bottom: 10px;
      margin-left: 0px;
    }
  }
  svg{
    font-size: 40px;
  }
  p{
    width: 100%;
    height: 120px;
    line-height: 30px;
    padding: 0 20px;
    font-size: 14px;
  }
}

</style>
